package cc.comac.mom.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import cc.comac.mom.api.QualityAsrCheckCorrigendumExplainService;
import cc.comac.mom.bean.QualityAsrCheckCorrigendumExplain;
import cc.comac.mom.config.OSSService;
import cc.comac.mom.util.ResultBean;
import cc.comac.mom.util.UploadPreviewData;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/QualityAsrCheckCorrigendumExplain")
public class QualityAsrCheckCorrigendumExplainController {

	@Autowired
	private QualityAsrCheckCorrigendumExplainService QualityAsrCheckCorrigendumExplainService;

	@Autowired
	private OSSService oSSService;

	@ApiOperation("勘误上传")
	@RequestMapping(value = "/saveCheckCorrigendumExplainUpload", method = RequestMethod.POST)
	public ResultBean saveCheckCorrigendumExplainUpload(@RequestBody QualityAsrCheckCorrigendumExplain qualityAsrCheckCorrigendumExplain) {
		ResultBean saveCheckCorrigendumExplainUpload = QualityAsrCheckCorrigendumExplainService
				.saveCheckCorrigendumExplainUpload(qualityAsrCheckCorrigendumExplain);
		return saveCheckCorrigendumExplainUpload;
	}
	
	@ApiOperation("勘误下载")
	@RequestMapping(value = "/saveCheckCorrigendumExplainUpload", method = RequestMethod.GET)
	public void saveCheckCorrigendumExplainDownload(@RequestParam Long corrigendumExplainId, HttpServletResponse response) throws IOException   {
		QualityAsrCheckCorrigendumExplain selectByCorrigendumExplainId = QualityAsrCheckCorrigendumExplainService.selectByCorrigendumExplainId(corrigendumExplainId);
		String corrigendumName = selectByCorrigendumExplainId.getInnerData().getCorrigendumName();
		String corrigendumPath = selectByCorrigendumExplainId.getInnerData().getCorrigendumPath();
//		UploadPreviewData.download(corrigendumPath, corrigendumName, response);
		oSSService.downFileFromOSS(response, corrigendumPath, corrigendumName);
	}
}
